The present invention is related generally to computer processors and more specifically to computer processor enhancements suitable for virtual machines.
The notion of a virtual machine has been a topic of academic research for many years. However, the idea has been popularized by Sun Microsystems, Inc. with its Java programming language and runtime environment. The Java virtual machine is software that acts as an interface between compiled Java binary code (known as bytecode) and the underlying hardware platform (e.g., a microprocessor) that actually implements the bytecodes. Once a Java virtual machine has been provided for a platform, any Java program can run on that platform.
As the name implies, a virtual machine is an abstraction (a virtual representation) of a physical processor and typically comprises virtual counterparts of a conventional processor. For example, the Java virtual machine specifies elements such as an instruction set, a set of registers, a stack, a “garbage heap,” and a method area. The real implementation of this abstract or logically defined processor is the native machine code executed by the real processor or be built into the microchip processor itself (so-called microcode).
An area in which the virtual machine is finding application is in the use of smartcards. Typically, a smartcard is a card that is embedded with either a microprocessor and a memory chip or only a memory chip with non-programmable logic. A microprocessor-based smartcard can add, delete, and otherwise manipulate information on the card, and is readily adaptable to many functions. For example, the national health card of Taiwan is a general-purpose smartcard which can store multiple programs downloaded from multiple vendors. Other examples include a credit card which can hold multiple “loyalty” applications to reward the user for multiple purchases from a single vendor, and which can also function as an employee ID card. Java Card is based on the underlying technology of the Java programming language. The Java virtual machine specification and the language definition have been accommodated to make Java technology available in a smartcard.
The present invention is motivated in part by the potential benefits of virtual machine based smartcards and, in general, by the use of virtual machine technology in resource-limited environments such as the smartcard.
For example, a smartcard typically uses three kinds of memory: ROM (read-only memory), RAM (random-access memory), and EEPROM (electrically erasable programmable read-only memory). A programming language (e.g., Java) used in a virtual machine is an abstract language and typically uses a memory model that does not recognize different kinds of memory. The translation from the abstract memory space of the virtual machine environment to the physical memory contained in or connected to the smartcard is performed by the virtual machine.
Java is an object oriented language, and thus relies heavily on the creation and destruction of objects. In an object oriented language, there are no facilities for supporting procedures (i.e., functions without an associated object), so it is not possible to do procedural programming. Therefore, it is necessary to create, destroy, and call objects to perform a given task.
Typically, smartcards have very limited RAM capacity; 2K (bytes) to 4K is common. If the programming objects are created in the limited RAM, then it becomes very difficult to perform complex tasks because the amount of memory available for object creation is very limited. A smartcard typically has much more EEPROM capacity than RAM, usually on the order of 32K to 96K of EEPROM as compared to the 2K-4K of RAM. Consequently, the virtual machine uses EEPROM for instantiation of object instance data, and uses RAM only for the Java stack and “transient RAM arrays.”
The allocation of EEPROM memory for object instance data permits the creation of large programs because there is much more EEPROM capacity than RAM capacity. However, there is a substantial cost for this extra capacity. RAM typically requires one clock cycle to read or write data. EEPROM reads, likewise, typically are performed in one clock. EEPROM write operations, on the other hand, typically require about 4 mS to complete, or about 14,289 clock cycles running at 3.57 MHz! Object creation involves initialization of the data comprising the object, which require writes to the EEPROM. It can be appreciated therefore that object creation and object instance data updates is a very, very slow process.
Similarly, the virtual machine heap is allocated from EEPROM. The heap is a dynamic data structure which is constantly read and, more significantly, written. Thus, writing to dynamically allocated memory is a very slow process. Generally, any variable not on the stack will be allocated from the EEPROM heap, and so writes to non-stack variables will be very slow.
Another area of concern is in the area of providing adequate memory management. In the context of a smartcard environment, and other similarly constrained operating environments, system memory capacity is a very limited resource. Historically, limited memory capacity has always been a problem in processors, especially on multitasking systems where multiple users can run different programs simultaneously as if each user were the only person on the system. The earliest multitasking systems supported a method of multitasking memory called “swapping.” This system saves the entire executing state of a low priority program to a disk, thus freeing up memory to allow another, higher priority program to execute. Swapping can also take place when a program is idle, waiting for data transfer with a slow I/O device (e.g., tape drive) to complete.
Though swapping is effective in providing access to memory, the performance is less than optimal because the entire address space of the program must be swapped to and from the disk. The idea of swapping out entire programs evolved into the notion of “paging” where the address space of a program was divided into some number of fixed-size pages. Each of these pages could then be swapped out to disk and back, as required by the system, without having to swap out the entire program thus improving system performance.
Memory protection mechanism are needed when multiple programs are executing on the processor. Memory protection via hardware instructions has traditionally been implemented in one or two different ways: The first method was via extra data bits added to each machine word. This method required special hardware and was incompatible with industry standards, and was soon discontinued in favor of memory management logic. This method relies upon a component called a memory management unit (MMU) to implement memory protection. The MMU approach provides page-level granularity, usually on the order of 4 Kbytes and higher.
Another memory management technique concerns memory access speed. The “cache” is a high-speed memory and was originally envisioned as a slave to a slower core memory in such a way that in practical cases the effective access time is nearer that of the fast memory than that of the slow memory. Caches have traditionally been used to decrease the average access time of slower RAM memory, and have also been used in mechanical storage media such as disk drives.
There is a need to provide a suitable operating environment for operating a virtual machine in a smartcard environment and in general in any similar resource-limited environment other than in a smartcard application.